﻿using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbDepartmentsTest and is intended
    ///     to contain all TmdbDepartmentsTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbDepartmentsTest
    {
        /// <summary>
        ///     A test for TmdbDepartments Constructor
        /// </summary>
        [TestMethod]
        public void TmdbDepartmentsConstructorTest()
        {
            var target = new TmdbDepartments();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\departments.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbDepartments();
            var jsonContent = File.ReadAllText( "departments.json.txt" );
            var actual = await target.DeserializeJson<TmdbDepartments>( jsonContent );

            Assert.AreEqual( 3, actual.Departments.Count );

            Assert.AreEqual( "Writing", actual.Departments[ 0 ].DepartmentName );
            Assert.AreEqual( "Screenplay", actual.Departments[ 0 ].JobList[ 0 ] );
            Assert.AreEqual( "Author", actual.Departments[ 0 ].JobList[ 1 ] );

            Assert.AreEqual( "Directing", actual.Departments[ 1 ].DepartmentName );
            Assert.AreEqual( "Director", actual.Departments[ 1 ].JobList[ 0 ] );
            Assert.AreEqual( "Script Supervisor", actual.Departments[ 1 ].JobList[ 1 ] );
            Assert.AreEqual( "Other", actual.Departments[ 1 ].JobList[ 2 ] );
            Assert.AreEqual( "Layout", actual.Departments[ 1 ].JobList[ 3 ] );
            Assert.AreEqual( "Special Guest Director", actual.Departments[ 1 ].JobList[ 4 ] );

            Assert.AreEqual( "Lighting", actual.Departments[ 2 ].DepartmentName );
            Assert.AreEqual( "Lighting Technician", actual.Departments[ 2 ].JobList[ 0 ] );
            Assert.AreEqual( "Other", actual.Departments[ 2 ].JobList[ 1 ] );
        }
    }
}